package com.example.mapper;

import com.example.pojo.Dept;
import com.example.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Mapper
public interface EmpMapper {
   /**  原始分页方式 ，比较繁琐
   //获取总数据量
    @Select("select count(*) from tails.tb_emp")
    public Long count();

    //形参为 起始索引 和 每页显示记录数
    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time from tails.tb_emp " +
            "limit #{start},#{pageSize}")
    //分页操作后返回的是每一页的数据列表
    public List<Emp> page(Integer start,Integer pageSize);
    */


   //条件分页查询
    List<Emp> list(String name, Short gender, LocalDate begin,LocalDate end);

   //批量删除
    void delete(ArrayList ids);

    //添加员工
    void add(Emp emp);

    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time " +
            "from tails.tb_emp where  id = #{id}")
    Emp selectById(Integer id);

    void update(Emp emp);

    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time " +
            "from tails.tb_emp where username = #{username} and password = #{password}")
    Emp login(Emp emp);

    @Delete("delete from tb_emp where dept_id = #{deptId}")
    void deleteByDeptId(Integer deptId);
}
